package com.hit.sys.modular.user.factory;

import cn.hutool.core.util.ObjectUtil;
import com.hit.core.util.CryptogramUtil;
import com.hit.sys.core.enums.AdminTypeEnum;
import com.hit.core.enums.CommonStatusEnum;
import com.hit.sys.core.enums.SexEnum;
import com.hit.sys.modular.user.entity.SysUser;

public class SysUserFactory {
    public static void fillAddCommonUserInfo(SysUser sysUser) {
        fillBaseUserInfo(sysUser);
        sysUser.setAdminType(AdminTypeEnum.NONE.getCode());
    }

    public static void fillBaseUserInfo(SysUser sysUser) {
        //密码为空则设置密码（密码都为哈希值哦）
        if (ObjectUtil.isEmpty(sysUser.getPassword())) {
            //没有密码则设置默认密码
            String password = "123456";
            //设置密码为Sm3的哈希值，这里代表保护密码的完整性
            sysUser.setPassword(CryptogramUtil.doHashValue(password));
        }

        if (ObjectUtil.isEmpty(sysUser.getSex())) {
            sysUser.setSex(SexEnum.NONE.getCode());
        }

        sysUser.setStatus(CommonStatusEnum.ENABLE.getCode());
    }

}
